cmake_minimum_required (VERSION 2.8) 
project (mrpd_simple_test)
enable_testing()

set (CPPUTEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../thirdparty/cpputest )
set (SRC_DIR "../.." )
add_definitions(-DMRP_CPPUTEST)

include_directories( . "../../../common" ${CPPUTEST_DIR}/include )
file(GLOB CPPUTEST_SRC *.cpp)
file(GLOB MRPD_SRC ${SRC_DIR}/mrp.c ${SRC_DIR}/mvrp.c ${SRC_DIR}/mmrp.c ${SRC_DIR}/msrp.c "../../../common/parse.c" "../../../common/eui64set.c" )

# memory leak test
add_definitions(-DCPPUTEST_USE_MEM_LEAK_DETECTION)

if(APPLE)
  set(CPPUTEST_C_FLAGS "${CPPUTEST_C_FLAGS} -include ${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorMallocMacros.h")
  set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -include ${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorNewMacros.h")
  set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -include ${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorMallocMacros.h")
  include_directories( include ${CPPUTEST_DIR}/include/Platforms/Gcc )
  add_executable (mrpd_simple_test ${MRPD_SRC} ${CPPUTEST_SRC} )
  target_link_libraries(mrpd_simple_test CppUTest CppUTestExt)
elseif(UNIX)
  set(CPPUTEST_C_FLAGS "${CPPUTEST_C_FLAGS} -include ${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorMallocMacros.h")
  set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -include ${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorNewMacros.h")
  set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} -include ${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorMallocMacros.h")
  include_directories( include ${CPPUTEST_DIR}/include/Platforms/Gcc )
  link_directories(mrpd_simple_test ${CPPUTEST_DIR}/src/CppUTest ${CPPUTEST_DIR}/src/CppUTestExt )
  add_executable (mrpd_simple_test ${MRPD_SRC} ${CPPUTEST_SRC} mrp_doubles.c)
  target_link_libraries(mrpd_simple_test CppUTest CppUTestExt)
elseif(WIN32)
  set(CPPUTEST_C_FLAGS "${CPPUTEST_C_FLAGS} /FI${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorMallocMacros.h")
  set(CPPUTEST_CXX_FLAGS "${CPPUTEST_CXX_FLAGS} /FI${CPPUTEST_DIR}/include/CppUTest/MemoryLeakDetectorMallocMacros.h")
  if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
    link_directories(mrpd_simple_test $ENV{WPCAP_DIR}/Lib/x64 ${CPPUTEST_DIR}/src/CppUTest ${CPPUTEST_DIR}/src/CppUTestExt)
  elseif( CMAKE_SIZEOF_VOID_P EQUAL 4 )
    link_directories(mrpd_simple_test $ENV{WPCAP_DIR}/Lib ${CPPUTEST_DIR}/src/CppUTest ${CPPUTEST_DIR}/src/CppUTestExt)
  endif()

  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  include_directories( include $ENV{WPCAP_DIR}/Include )
  add_executable (mrpd_simple_test ${MRPD_SRC} ${CPPUTEST_SRC} ${SRC_DIR}/que.c mrp_doubles.c)
  target_link_libraries(mrpd_simple_test wpcap Iphlpapi Ws2_32 CppUTest CppUTestExt)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CPPUTEST_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPPUTEST_CXX_FLAGS}")

add_test( test_mrpd mrpd_simple_test -v )
